1 using UnityEngine;
2
3 public
class PlayerVariables
4 {
5     
private static Color[] playerColors = new Color[] {Color.yellow, Color.red, Color.green, Color.cyan};
6     
private static string[] playerColorNames = new string[] {"yellow", "red", "green", "cyan"};
7     
private static Material[] playerMaterials = new Material[playerColors.Length];
8
9     
public static Color GetColor(int playerId)
10     {
11         
if (playerId <= 0)
12         {
13             
return Color.white;
14         }
15         
return playerColors[playerId%playerColors.Length];
16     }
17
18     
public static string GetColorName(int playerId)
19     {
20         
if (playerId <= 0)
21         {
22             
return "none";
23         }
24         
return playerColorNames[playerId%playerColors.Length];
25     }
26
27     
public static Material GetMaterial(Material original, int playerId)
28     {
29         Material result = playerMaterials[playerId%playerMaterials.Length];
30
31         
if (result == null)
32         {
33             result =
new Material(original);
34             result.color = GetColor(playerId);
35             playerMaterials[playerId%playerMaterials.Length] = result;
36         }
37
38         
return result;
39     }
40 }



Trò chơi Tic-Tac-Toe, game đánh caro full source code 53.447 lượt xem

Gõ tìm kiếm nhanh...